package com.hllxd.hism.star.basic.service.model.alarm;

import com.hllxd.hism.star.basic.service.constant.alarm.AlarmErrorTypeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @description 校验异常信息BO
 * @auhtor wuguangxi
 * @date 2022/1/5 15:51
 **/
@Data
@NoArgsConstructor
public class AlarmErrorBO {

    /**
     * 规则id
     */
    private Integer ruleId;

    /**
     * 规则明细
     */
    private AlarmRule alarmRule;

    private String rowKey;

    private String uniqueKey;

    /**
     * 规则名称
     */
    private String ruleName;

    /**
     * 优先级
     */
    private Integer priority;

    /**
     * 告警日期
     */
    private String date;

    /**
     * 异常信息
     */
    private AlarmErrorTypeEnum errorType;

    /**
     * 维度组合
     */
    private String dimCombine;

    /**
     * 维度组合名称
     */
    private String dimCombineName;

    /**
     * 维度值组合
     */
    private String dimDescartes;

    /**
     * 维度值组合名称
     */
    private String dimDescartesName;

    /**
     * 校验类型 1:01报警，2:绝对值，3：波动值
     */
    private int alarmType;

    /**
     * 时间频率
     */
    private String timeGranularity;

    /**
     * 计算类型
     */
    private String calculateType;

    /**
     * 时间段
     */
    private String timePeriod;

    /**
     * 范围百分比
     */
    private Double range;

    /**
     * 连续出现次数
     */
    private int continueTimes;

    /**
     * 指标
     */
    private String indicator;

    /**
     * 告警级别
     */
    private String alarmLevels;

    /**
     * 运算符号
     */
    private String operator;

    /**
     * 指标值
     */
    private Double indicatorValue;

    /**
     * 增长/下降
     */
    private String trend;

    /**
     * 计算值
     */
    private Double calculateValue;

    /**
     * 对比值数值
     */
    private Double compareNumber;

    /**
     * 组合校验指标
     */
    private List<String> combineIndicators;

    /**
     * 连续性校验时，前若干次校验结果
     */
    private List<AlarmErrorBO> lastPeriodAlarms;

    public AlarmErrorBO(AlarmRuleDetailBO alarmRuleDetailBO, AlarmErrorTypeEnum errorType, String date, Double indicatorValue){
        fillFromRuleDetail(alarmRuleDetailBO);
        this.errorType = errorType;
        this.date = date;
        this.indicatorValue = indicatorValue;
    }

    public AlarmErrorBO(AlarmRuleDetailBO alarmRuleDetailBO, AlarmErrorTypeEnum errorType, String date, Double indicatorValue, String trend, Double calculateValue){
        fillFromRuleDetail(alarmRuleDetailBO);
        this.errorType = errorType;
        this.indicatorValue = indicatorValue;
        this.date = date;
        this.trend = trend;
        this.calculateValue = calculateValue;
    }

    private void fillFromRuleDetail(AlarmRuleDetailBO alarmRuleDetailBO){
        this.alarmRule = alarmRuleDetailBO.getAlarmRule();
        this.ruleId = alarmRuleDetailBO.getRuleId();
        this.timePeriod = alarmRuleDetailBO.getAlarmRule().getTimePeriod();
        this.rowKey = alarmRuleDetailBO.getRowKey();
        this.uniqueKey = alarmRuleDetailBO.getUniqueKey();
        this.ruleName = alarmRuleDetailBO.getAlarmRule().getName();
        this.dimCombine = alarmRuleDetailBO.getDimCombine();
        this.alarmType = alarmRuleDetailBO.getAlarmType();
        this.dimDescartes = alarmRuleDetailBO.getDimDescartes();
        this.timeGranularity = alarmRuleDetailBO.getTimeGranularity();
        this.calculateType = alarmRuleDetailBO.getCalculateType();
        this.range = alarmRuleDetailBO.getRange();
        this.continueTimes = alarmRuleDetailBO.getContinueTimes();
        this.indicator = alarmRuleDetailBO.getIndicator();
        this.alarmLevels = alarmRuleDetailBO.getAlarmLevels();
        this.operator = alarmRuleDetailBO.getOperator();
        this.priority = alarmRuleDetailBO.getAlarmRule().getPriority();
    }
}
